$(document).ready(function(){ if ( $('.js-toggle-overlay').length ) { $( '.js-toggle-overlay' ).on( 'click', function ( event ) { event.preventDefault(); event.stopPropagation(); if ( $('#overlay').css('display') == 'none' ) { $('#overlay').fadeIn('fast'); }else if (($('#overlay').css('display') == 'block' && $('#login-overlay').css('display') == 'none') || ($('body').hasClass('logged-in') && $('.js-toggle-overlay').hasClass('open')) ) { $('#overlay').fadeOut('fast'); } $('.sub-menu').toggle('slide', { direction: 'left' }, 500, function(){ $('.js-toggle-overlay').toggleClass('open'); }); }); } if ( $('.login-box-trigger').length ) { $( '.login-box-trigger' ).on( 'click', function ( event ) { event.preventDefault(); event.stopPropagation(); if ( $('#overlay').css('display') == 'none' ) { $('#overlay').fadeIn('fast'); }else if ($('#overlay').css('display') == 'block' && $('.sub-menu').css('display') == 'none') { $('#overlay').fadeOut('fast'); } $('#login-overlay').slideToggle(); }); } if ( $('#country-options').length ) { var currentLang = getCookie("language"); $('#country-options').on('change', function (e) { var langSelected = $("option:selected", this).val(); var url = replaceUrlParam(location.href, "language", langSelected); window.location.href = url; }); $("#country-options option[value='"+currentLang+"']").prop('selected', true); } // Create a clone of the nav-wrapper, right next to original.. if ( $('.stick-element').length ) { $('.stick-element').addClass('original').clone().insertAfter('.stick-element').addClass('cloned').css('position','fixed').css('top','0').css('margin-top','0').css('z-index','500').removeClass('original').hide(); scrollIntervalID = setInterval(stickIt, 10); } }); function stickIt() { var orgElementPos = $('.original').offset(); if ($('.original').attr('data-offset')) { var offsetSettings = parseInt($('.original').attr('data-offset')); orgElementTop = orgElementPos.top + offsetSettings; }else{ orgElementTop = orgElementPos.top; } if ($(window).scrollTop() >= (orgElementTop)) { // scrolled past the original position; now only show the cloned, sticky element. // Cloned element should always have same left position and width as original element. orgElement = $('.original'); coordsOrgElement = orgElement.offset(); leftOrgElement = coordsOrgElement.left; widthOrgElement = orgElement.css('width'); $('.cloned').css('left',leftOrgElement+'px').css('top',0).css('width',widthOrgElement).show(); $('.original').css('visibility','hidden'); } else { // not scrolled past the nav-wrapper; only show the original nav-wrapper. $('.cloned').hide(); $('.original').css('visibility','visible'); } } function replaceUrlParam(url, paramName, paramValue){ var pattern = new RegExp('('+paramName+'=).*?(&|$)') var newUrl=url if(url.search(pattern)>=0){ newUrl = url.replace(pattern,'$1' + paramValue + '$2'); } else{ newUrl = newUrl + (newUrl.indexOf('?')>0 ? '&' : '?') + paramName + '=' + paramValue } return newUrl } var enableAutoLoadGames = true;const GAMES_IMAGE_FORMAT_FALLBACK = []; var RecentGames = function() { var currentRecentGames = [], RecentGamesWrapper, BottomGamesWrapper; return{ init: function(){ RecentGamesWrapper = $('#recently-played'); BottomGamesWrapper = $('#bottom-nav-recent'); $('body').on('click', '.play-button', function(e){ var code = $(this).attr('data-code'); addRecentGame(code, $(this)); }); setRecentGames(); }, setRecentGames: function(){ return setRecentGames(); }, renderRecentGames: function(){ return renderRecentGames(); } }; function addRecentGame(code, that){ if ($.inArray( code, currentRecentGames) == -1) { currentRecentGames = currentRecentGames.filter(function(e){return e}); currentRecentGames.unshift(code); if (currentRecentGames.length > 6) { currentRecentGames.pop(); } callPlatformAPI( 'setparam', {name: 'recentgames', value:currentRecentGames.join(',') }).done(function(data) { renderRecentGames(); }); } } function renderRecentGames(){ currentRecentGames = currentRecentGames.filter(function(e){return e}); RecentGamesWrapper.find('.games-list').html(''); BottomGamesWrapper.find('.games-list').html(''); var games = GamesLobby.getGamesByCode(); if (currentRecentGames.length) { for (var i = 0; i <= currentRecentGames.length - 1; i++){ var code = currentRecentGames[i]; //jackpot += parseInt(games[code].jackpot); GamesLobby.renderGameBlock(games[code], i, RecentGamesWrapper.find('.games-list')); if (games[code]) { BottomGamesWrapper.find('.games-list').append("
\ \
\
\
\
"); } } }else{ RecentGamesWrapper.find('.games-list').html('

' +lang_played_no_games+'.

'); } } function setRecentGames(){ if (userLoggedIn === 'false') { return; } callPlatformAPI( 'getparam', {name: 'recentgames'}).done(function(data) { if (data.type == 'getparam') { var savedCodes = data.value.split(','); $.each(savedCodes, function(i, code){ currentRecentGames.push(code); }); } }); } }(); var GameFavourites = function() { var currentFavourites = [], FavouritesWrapper; return{ init: function(catContainer){ FavouritesWrapper = (typeof catContainer == 'undefined') ? $('#favourite-games') : $('.games-lobby'); $('body').on('click', '.favourite-trigger', function(e){ e.preventDefault(); var code = $(this).attr('data-code'); if ($(this).hasClass('fav-added')) { removeFavourite(code, $(this)); }else{ addFavourite(code, $(this)); } }); setFavourites(); }, setFavourites: function(){ return setFavourites(); }, getFavourites: function(){ return currentFavourites; }, renderFavourites: function(){ return renderFavourites(); }, getFavouritesWrapper: function(){ return FavouritesWrapper; } }; function renderFavourites(){ currentFavourites = currentFavourites.filter(function(e){return e}); FavouritesWrapper.find('.games-list').html(''); var games = GamesLobby.getGamesByCode(); if (currentFavourites.length) { for (var i = 0; i <= currentFavourites.length - 1; i++){ var code = currentFavourites[i]; //jackpot += parseInt(games[code].jackpot); GamesLobby.renderGameBlock(games[code], i, FavouritesWrapper.find('.games-list')); } }else{ FavouritesWrapper.find('.games-list').html('

'+EmptyFavourite+'

'); } } function removeFavourite(code, that){ currentFavourites.splice($.inArray(code, currentFavourites),1); callPlatformAPI( 'setparam', {name: 'favourites', value:currentFavourites.toString() }).done(function(data) { $('.favourite-button[data-code="'+code+'"]').removeClass('fav-added'); if($('.favorites-trigger').hasClass('selected')){ renderFavourites(); } }); } function addFavourite(code, that){ currentFavourites = currentFavourites.filter(function(e){return e}); currentFavourites.unshift(code); callPlatformAPI( 'setparam', {name: 'favourites', value:currentFavourites.join(',') }).done(function(data) { $('.favourite-button[data-code="'+code+'"]').addClass('fav-added'); //renderFavourites(); }); } function setFavourites(){ if (userLoggedIn === 'false') { return; } callPlatformAPI( 'getparam', {name: 'favourites'}).done(function(data) { if (data.type == 'getparam') { var savedCodes = data.value.split(','); $.each(savedCodes, function(i, code){ currentFavourites.push(code); }); } }); } }(); var GamesLobby = function() { var AllGamesObj = {}, gamesByCode = [], InitCategoryGames, SearchControls, CategoryList, GameList, PaginateIncrement, InitialPaginateStart, PaginateStart, PaginateEnd, RecentlyPlayedWrapper, SearchResultsWrapper, ProvidersWrapper, FavouritesWrapper, CurrentFavourites, CategoryWrapper, SlotsSwitch, intersectObserverInstanceAutoLoadGames, currentGamesListedIntersectObserverAutoLoadGames, FilterSearchStr, FilterProvider, jpCnt = 0; return { init: function(DataURLStr, InitCat, LobbyWrapper, paginateStart, paginateIncrement, searchControls, categoryWrapper, slotsSwitch) { InitialPaginateStart = paginateStart; PaginateStart = InitialPaginateStart; PaginateEnd = paginateIncrement; PaginateIncrement = paginateIncrement; SearchControls = $(searchControls); FavouritesWrapper = GameFavourites.getFavouritesWrapper(); CurrentFavourites = GameFavourites.getFavourites(); CategoryWrapper = (typeof categoryWrapper !== 'undefined') ? $('#'+categoryWrapper) : ''; SlotsSwitch = (typeof slotsSwitch === 'undefined') ? 'true' : 'false'; if (enableAutoLoadGames) { SlotsSwitch = 'false'; } if(DataURLStr == 'sharedGamesAPI'){ var brandID = $('body').attr('data-brand'); const deviceType = (isMobile == 1) ? "MobileHTML" : "Desktop"; const sharedGamesAPI = new SharedGamesAPI(); sharedGamesAPI.processGameData(brandID, deviceType, InitCat) .then(processedGameData => { parseResponseNew(processedGameData, InitCat, LobbyWrapper); }) .catch(error => { console.error("Error processing game and categories data:", error); }); } else{ $.ajax({ type: "GET", url: DataURLStr, dataType: "xml", success: function(responseXML) { parseResponse(responseXML, InitCat, LobbyWrapper); } }); } }, getAllGamesObject: function() { return AllGamesObj; }, getGamesByCode: function() { return gamesByCode; }, renderGameBlock: function(gameObj, i, GameListWrapper) { return renderGameBlock(gameObj, i, GameListWrapper); } } function renderProvidersPopup(providersArray){ var LetterGroupedProviders = []; var i = 0; var letters = ['1','4','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']; $.each(providersArray, function(index, value){ var firstLetter = value.charAt(0).toLowerCase(); if(!LetterGroupedProviders[firstLetter]) LetterGroupedProviders[firstLetter] = [], i++; LetterGroupedProviders[firstLetter].push(value); }); $.each(letters, function(index, letter){ $('#providers-list').append('
  • '+letter+'\ \
  • \ '); if (LetterGroupedProviders[letter]) { $.each(LetterGroupedProviders[letter], function(i, provider){ $('#providers-list li#'+letter+' ul.items-list').append('
  • '+provider+'
  • '); }); } }); $('#providers-list li ul.items-list li').on('click', function(){ var provider = $(this).attr('data-provider'); gamesByParam('provider='+provider+'&filter=az', $('#provider-games .games-list'), $("#more-provider-games"),provider); $('#search-panel').show(); $('#controls-panel').hide(); ProvidersWrapper.show(); ProvidersWrapper.find('.games-list').html(''); ProvidersWrapper.find('#provider-name').html(provider); RecentlyPlayedWrapper.hide(); FavouritesWrapper.hide(); }); } function renderProvidersList(providersArray){ $.each(providersArray, function(index, provider){ $('#providers-list').append('
  • '+provider+'
  • '); }); $("#providers-list").on("click", ".init", function() { $(this).closest("ul").children('li:not(.init)').toggle(); }); var allOptions = $("#providers-list").children('li:not(.init)'); $("#providers-list").on("click", "li:not(.init)", function() { allOptions.removeClass('selected'); $(this).addClass('selected'); $("#providers-list").children('.init').html($(this).html()); allOptions.toggle(); $('.games-lobby .games-list').html(''); var provider = $(this).attr('data-provider'); gamesByParam('provider='+provider+'&filter=az', $('.games-lobby .games-list'), $("#more-games"), provider); }); } function renderCategories(AllCategories, InitCat){ var SlotsGames, defaultTop = (isMobile == 1) ? 'mobiletop' : 'top'; topCategoryByCountry = $('body').data('country-top-category') || defaultTop; $(AllCategories).each(function(i, category) { var selected = '', categoryCodeLang = category.code; if(category.code.indexOf('top') > -1 || category.code.indexOf('mobiletop') > -1) { if(category.code === topCategoryByCountry) { categoryCodeLang = 'top'; } else { return; } } if (category.code == 'slots' || category.code == 'mobileslots') { SlotsGames = category; } if (InitCat == category.code) { selected = 'selected'; InitCategoryGames = category.games; } if (category.code != 'home' && category.code != 'mobilehome' && categories_lang[categoryCodeLang] != undefined) { CategoryList.attr('name', InitCat); CategoryList.append('
  • '+categories_lang[categoryCodeLang]+'
  • '); } }); if(CategoryWrapper == ''){ CategoryList.append("
  • "+lang_favourites+"
  • \
  • "+lang_sort_provider+"
  • \
  • "+lang_game_search+"
  • "); }else{ if(userLoggedIn == 'true'){ CategoryList.append("
  • "+lang_favourites+"
  • "); } } if ($('.stick-element').length) { $('.stick-element').addClass('original').clone().insertAfter('.stick-element').addClass('cloned').css('position','fixed').css('top','0').css('margin-top','0').css('z-index','500').removeClass('original').hide(); scrollIntervalID = setInterval(stickIt, 10); } viewMoreCategorySwitchHandler(SlotsGames); $(AllCategories).each(function(i, category) { $('.category-list li[data-category="'+category.code+'"]').on('click', function(){ var viewMoreButtonElement = document.querySelector('#more-games'); intersectObserverInstanceAutoLoadGames.observe(viewMoreButtonElement); if (category.code === 'mobileslots') { intersectObserverInstanceAutoLoadGames.disconnect(); } if (category.code == 'top' || category.code == 'mobiletop') { categoryTabSwitch(category, paginate); $('#view_all_games').hide(); if (!enableAutoLoadGames) { $("#more-games").hide(); } $('.slots-trigger').show(); viewMoreCategorySwitchHandler(SlotsGames); }else if(category.code == 'slots' || category.code == 'mobile'){ intersectObserverInstanceAutoLoadGames.disconnect(); categoryTabSwitch(category, paginate); $('#view_all_games').show(); $("#more-games").show(); $('.slots-trigger').hide(); viewAllGames($('#view_all_games'), category); }else{ $('#view_all_games').hide(); $('.slots-trigger').hide(); $("#more-games").show(); categoryTabSwitch(category, paginate); } if($("[name='lobbyAnchor']").length){ $('html,body').animate({ scrollTop: $("[name='lobbyAnchor']").offset().top}, 'slow'); } // Reset providers once selecting category $("#providers-list").children('.init').html('Select provider'); }); }); } function viewAllGames(button, games){ $(button).click(function(){ $(button).hide(); renderGames(games.games, GameList, false); }); } function viewMoreCategorySwitchHandler(category){ $('.slots-trigger').on('click', function(){ $('.slots-trigger').hide(); $("#more-games").show(); $('#view_all_games').show(); categoryTabSwitch(category, paginate); viewAllGames($('#view_all_games'), category); }); } function categoryTabSwitch(category, paginate){ $('.category-list li').removeClass('selected'); $('.category-list li[data-category="'+category.code+'"]').addClass('selected'); $('.games-list.main-lobby').html(''); PaginateStart = 0; PaginateEnd = PaginateIncrement; renderGames(category.games, GameList, true); paginate(category.games, $("#more-games"), GameList); } function renderGameBlock(gameObj, i, GameListWrapper){ if (typeof gameObj !== "undefined") { CurrentFavourites = GameFavourites.getFavourites(); var JackpotWrapper; if(gameObj.jackpot && gameObj.jackpot != "0") { JackpotWrapper = "
    Loading...
    "; jpCnt++; }else{ JackpotWrapper = ""; } if (isMobile == 1) { var PlayBtn = "
    "; }else{ var PlayBtn = "
    "; } var gameImage = loadImage(gameObj); var FavAdded = ($.inArray( gameObj.code, CurrentFavourites) == -1 ) ? '' :'fav-added'; var span = (i == 0 || i == 19) ? 'span-2' :''; var FavBtn = (userLoggedIn == 'false') ? "" :"
    "; var GameBlock = "
    \ "+gameImage+"\ "+JackpotWrapper+"\
    \
    "+gameObj.title+"
    \
    \ "+PlayBtn+"\ "+FavBtn+"\
    \
    \
    "; $(GameBlock).hide().appendTo(GameListWrapper).fadeIn(1000); if(jpCnt) { if(typeof TickerStart != "undefined") TickerStart(); } } } function loadImage(gameData){ var elSubCategory = gameData?.el && gameData?.el.getAttribute("sub_category"); var jsonSubcategory = gameData?.subCategory_code; var enableAnimated = (elSubCategory && elSubCategory.includes("animated")) || (jsonSubcategory && jsonSubcategory.includes("animated")); if (enableAnimated) { var image = new Image(); var svgImagePath = gameData.image.substr(0, gameData.image.lastIndexOf("/")); var url_image_svg = svgImagePath + '/' + gameData.code + '.svg'; image.src = url_image_svg; return ""; } else { var image = gameData.image; return ``; } } function renderGames(GamesArray, GameListWrapper, paginate){ if(!GamesArray) return; if(GamesArray.length <= 39){ $('#more-games').hide(); } jpCnt = 0; if (paginate) { if(GamesArray.length < PaginateEnd) PaginateEnd = GamesArray.length; $(window).unbind('scroll'); for (var i = PaginateStart; i < PaginateEnd; i++) { renderGameBlock(GamesArray[i], i, GameListWrapper); } }else{ $('#more-games').hide(); var endCount; var startCount; for (var i = PaginateEnd; i < (PaginateEnd + 39); i++) { renderGameBlock(GamesArray[i], i, GameListWrapper); } PaginateEnd = PaginateEnd + 39; $(window).scroll(function() { var end = $('.scroll-offset-target').offset().top; var viewEnd = $(window).scrollTop() + $(window).height(); var distance = end - viewEnd; if (distance < 150){ startCount = PaginateEnd; endCount = PaginateEnd + 27; for (var i = startCount; i < endCount; i++) { renderGameBlock(GamesArray[i], i, GameListWrapper); } PaginateEnd = PaginateEnd + 27; } }); } currentGamesListedIntersectObserverAutoLoadGames = GamesArray; // Restart state of buttons $('#view_all_games').css("visibility", "visible"); $('#view_all_games').show(); $('#more-games').css("visibility", "visible"); $('#more-games').show(); } function renderLobbyStructure(AllGamesObj, InitCat, LobbyWrapper){ if(CategoryWrapper == ''){ var CategoryStructure = $( "
    \ \
    " ); }else{ var CategoryStructure = $( "" ); CategoryWrapper.append(CategoryStructure); } if ((InitCat == 'home' || InitCat == 'mobilehome') && userLoggedIn == 'false') { var MoreGamesBtn = ""+viewMoreGames+""; }else{ var SlotTrigger = ''; var PaginateDisplayState = 'inline-block'; if(SlotsSwitch == 'true'){ SlotTrigger = ""+viewMoreGames+""; PaginateDisplayState = 'none'; } var MoreGamesBtn = "
    \ \ "+SlotTrigger+"\ "+viewMoreGames+"\
    "; if(CategoryWrapper == ''){ $(LobbyWrapper).append(CategoryStructure); } } var GamesStructure = $("
    "+MoreGamesBtn); $(LobbyWrapper).append(GamesStructure); CategoryList = $('.category-list'); GameList = $('.main-lobby'); renderCategories(AllGamesObj.categories, InitCat); renderGames(InitCategoryGames, GameList, true); paginate(InitCategoryGames, $("#more-games"), GameList); if(CategoryWrapper != ''){ initSearch(SearchControls, $('.games-lobby .games-list'), true); renderProvidersList(AllGamesObj.providers); initClickHandlers(); }else{ GameFavourites.renderFavourites(); renderProvidersPopup(AllGamesObj.providers); RecentlyPlayedWrapper = $('#recently-played'); SearchResultsWrapper = $('#search-results'); ProvidersWrapper = $('#provider-games'); initClickHandlers(); initSearch(SearchControls, $('#search-results .games-list'), false); RecentGames.renderRecentGames(); } if (enableAutoLoadGames) { var viewMoreButtonElement = document.querySelector('#more-games'); if (viewMoreButtonElement) { if (intersectObserverInstanceAutoLoadGames != undefined) { intersectObserverInstanceAutoLoadGames.disconnect(); } else { intersectObserverInstanceAutoLoadGames = new IntersectionObserver(intersectionGamesList); } intersectObserverInstanceAutoLoadGames.observe(viewMoreButtonElement); } } } function intersectionGamesList(entries, observer) { if (currentGamesListedIntersectObserverAutoLoadGames) { var totalGames = currentGamesListedIntersectObserverAutoLoadGames.length; if (entries && entries.length > 0 && entries[0].isIntersecting) { GameList = $('.main-lobby'); buttonSelector = $("#more-games"); var missingGamesToDisplay = PaginateStart < totalGames; var allGamesAlreadyDisplayed = PaginateEnd + PaginateIncrement > totalGames; if (missingGamesToDisplay) { paginateOnClick(currentGamesListedIntersectObserverAutoLoadGames, buttonSelector, GameList); } if (allGamesAlreadyDisplayed) { // all games already displayed, so does not make sense to display it buttonSelector.css("visibility", "hidden"); buttonAllSelector = $("#view_all_games"); if (buttonAllSelector) { buttonAllSelector.css("visibility", "hidden"); } } } } } function parseResponseNew(response, initCat, LobbyWrapper) { AllGamesObj = { categories: response.categories, games: response.games, providers: response.providers, allGames: response.games, gamesBySubcat: [], currentCatGamesGroupedBySubcat: [], gamesByCat: [], subcatGameIndexesInAllGamesDataset: [], gamesWithoutSubcat: [], gamesByProvider: {} }; $(response.games).each(function(i, game) { gamesByCode[game.code] = game; }); if ($('.games-lobby').length) { renderLobbyStructure(AllGamesObj, initCat, LobbyWrapper); } } function parseResponse(responseXML, InitCat, LobbyWrapper) { AllGamesObj = { categories: [], games: [], providers: [] }; var providersArr = []; $(responseXML).find('gametype').each(function(i, category) { AllGamesObj.categories.push({ title: $(category).find("name").text(), code: $(category).find("name").attr("filter"), games: [] }); $(category).find('item').each(function(i2, game) { var gameObj = buildGameObject(game); AllGamesObj.categories[i].games.push(gameObj); AllGamesObj.games.push(gameObj); AllGamesObj.providers.push(gameObj.provider); gamesByCode[$(game).attr("launchcode")] = gameObj; }); }); $.each(AllGamesObj.providers, function(i, e) { if ($.inArray(e, providersArr) == -1 && e != "") providersArr.push(e); }); AllGamesObj.providers = makeUnique(AllGamesObj.providers); if ($('.games-lobby').length) { renderLobbyStructure(AllGamesObj, InitCat, LobbyWrapper); } const urlParams = new URLSearchParams(window.location.search); const urlProvider = urlParams.get('provider'); if (urlProvider) { $('.search-providers').trigger('click'); setTimeout(() => { const normalizedProvider = urlProvider.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase()); const $providerElement = $('#providers-list [data-provider="' + normalizedProvider + '"]'); $providerElement.click(); }, 0); } } function buildGameObject(game){ var gameObj = { title: $(game).attr("gname"), description: unescape(decodeURIComponent($(game).attr("description"))).replace(/\+/g, " "), code: $(game).attr("launchcode"), image: $(game).attr("g_img"), provider: $(game).attr("provider"), launch: $(game).attr("g_link"), curSym: $(game).attr("cursym"), currency: $(game).attr("currency"), jackpot: $(game).attr("jpamount"), rtp: $(game).attr("rtp"), funsupp: $(game).attr("fun_supported"), play_fun_text : lang_play_fun, play_real_text : lang_play_real, gHot : $(game).attr("ghot"), gNew : $(game).attr("gnew"), el: game }; return gameObj; } function clearSearch($searchInputBox, $searchInputClear, $gameListWrapper, IntegratedSearch) { PaginateStart = InitialPaginateStart; PaginateEnd = PaginateIncrement; $searchInputBox.val(""); $searchInputClear.hide(); $gameListWrapper.html(''); // Reset filters FilterSearchStr = ''; FilterProvider = undefined; // Reset providers once selecting category $("#providers-list").children('.init').html('Select provider'); $('.search-input-btn').show(); if(!IntegratedSearch){ RecentlyPlayedWrapper.show(); FavouritesWrapper.show(); SearchResultsWrapper.hide(); ProvidersWrapper.hide(); }else{ renderGames(InitCategoryGames, GameList, true); } } /** * Needs to set previously FilterSearchStr, FilterProvider * TODO Add support for filtering by category */ function applyFilterLogic() { var games = AllGamesObj.games; var searchGamesArr = []; function arrayContains(arr, val, equals) { var i = arr.length; while (i--) { if (equals(arr[i], val)) { return true; } } return false; } function removeDuplicates(arr, equals) { var originalArr = arr.slice(0); var i, len, j, val; arr.length = 0; for (i = 0, len = originalArr.length; i < len; ++i) { val = originalArr[i]; if (!arrayContains(arr, val, equals)) { arr.push(val); } } } function thingsEqual(thing1, thing2) { return thing1.place === thing2.place && thing1.title === thing2.title; } removeDuplicates(games, thingsEqual); games = games.sort(function(a, b) { var A = a.title.toLowerCase(); var B = b.title.toLowerCase(); if (A < B) { return -1; } else if (A > B) { return 1; } else { return 0; } }); var hiddenCategory = AllGamesObj.categories.find(category => category.code === 'hidden'); var hiddenGamesCode = hiddenCategory?.games.map(game => game.code) || []; // Filtering by search string for (var i = 0; i < games.length; i++) { var game = AllGamesObj.games[i]; if (game.title.toLowerCase().search(FilterSearchStr) > -1 && !hiddenGamesCode.includes(game.code)) { searchGamesArr.push(game); } }; // Filtering by provider if (!!FilterProvider) { searchGamesArr = searchGamesArr.filter(f => f.provider == FilterProvider); } return searchGamesArr; } function initSearch(SearchControlsWrapper, SearchContainer, IntegratedSearch) { $parentEl = SearchControlsWrapper, $searchInputBox = $parentEl.find(".search-input-box"), $searchInputClear = $parentEl.find(".search-input-clear"), $searchInputBtn = $parentEl.find(".search-input-btn"), $gameListWrapper = SearchContainer, searchGamesArr = [], searchStr = ""; $parentEl.find(".search-input-clear").click(function(e) { clearSearch($searchInputBox, $searchInputClear, $gameListWrapper, IntegratedSearch); }); $searchInputBox.keyup(function(e) { $('.search-input-btn').hide(); searchStr = this.value.toLowerCase(); if(!searchStr) { searchStr = ""; clearSearch($searchInputBox, $searchInputClear, $gameListWrapper, IntegratedSearch); return; } FilterSearchStr = searchStr; if(e.keyCode != 38 && e.keyCode != 40 && e.keyCode != 13) { $searchInputClear.show(); searchGamesArr = applyFilterLogic(); if (searchStr.replace(/ /g,'').length > 2) { if(!IntegratedSearch){ RecentlyPlayedWrapper.hide(); FavouritesWrapper.hide(); ProvidersWrapper.hide(); SearchResultsWrapper.show(); } if(!searchGamesArr.length) { $gameListWrapper.html('

    ' +lang_game_search+'.

    '); } else { PaginateStart = InitialPaginateStart; PaginateEnd = PaginateIncrement; $gameListWrapper.html(''); renderGames(searchGamesArr, $gameListWrapper, true); } } } }); } function initClickHandlers(){ $('.search-trigger').on('click', function(){ clearSearch($('.search-input-box'), $('.search-input-clear'), $('#search-results .games-list')); $('body').css('position', 'fixed'); $('#games-search-panel').show(); $('body').attr('data-active-panel', 'games-search-panel'); $('#search-panel').show(); $('#controls-panel').hide(); $('.search-input-box').focus(); }); $('.search-providers').on('click', function(){ $('body').css('position', 'fixed'); $('#games-search-panel').show(); $('#search-panel').hide(); $('#controls-panel').show(); }); $('#close-overlay').on('click', function(){ $('body').css('position', 'initial'); $('#games-search-panel').hide(); $('body').removeAttr('data-active-panel'); }); $('#open-settings').on('click', function(){ $('#search-panel').toggle(); $('#controls-panel').toggle(); }); $('.favorites-trigger').on('click', function(){ $('#view_all_games').hide(); $('#more-games').hide(); $('.category-list li').removeClass('selected'); $(this).addClass('selected'); if(CategoryWrapper != ''){ GameFavourites.renderFavourites(); }else{ clearSearch($('.search-input-box'), $('.search-input-clear'), $('#search-results .games-list')); $('body').css('position', 'fixed'); $('#games-search-panel').show(); $('#search-panel').show(); $('#recently-played').hide(); $('#controls-panel').hide(); GameFavourites.renderFavourites(); } }); if (getUrlParameter('search')) { var searchString = getUrlParameter('search'); $('.search-trigger').trigger( "click" ); setTimeout(function(){ $('.search-input-box').val(searchString).trigger('keyup'); $('.search-input-box').trigger('keyup'); }, 1000); } } function paginate(games, buttonSelector, wrapperSelector){ buttonSelector.unbind(); buttonSelector.attr('data-paginateStart', PaginateStart); buttonSelector.attr('data-paginateEnd', PaginateEnd); buttonSelector.on('click', function(){ paginateOnClick(games, buttonSelector, wrapperSelector); }); } function paginateOnClick(games, buttonSelector, wrapperSelector) { PaginateStart = (parseInt(PaginateStart)+parseInt(PaginateIncrement)); PaginateEnd = (parseInt(PaginateEnd)+parseInt(PaginateIncrement)); renderGames(games, wrapperSelector, true); buttonSelector.attr('data-paginateStart', PaginateStart); buttonSelector.attr('data-paginateEnd', PaginateEnd); } function makeUnique(list) { var result = []; $.each(list, function(i, e) { if ($.inArray(e, result) == -1) result.push(e); }); return result; } function gamesByParam(paramString, GameListWrapper, PaginateSelector,provider){ FilterProvider = provider; let games = applyFilterLogic(); if (!games.length) { GameListWrapper.html('

    ' +lang_game_search+'.

    '); } else { setTimeout(() => { $('div.games-list.main-lobby').html(''); PaginateStart = 0; PaginateEnd = PaginateIncrement; renderGames(games, GameListWrapper, true); paginate(games, PaginateSelector, GameListWrapper); }, 500); } } }(); // DOM ready $(window).on("load", function() { if ($('.games-lobby').length) { var initCat = $('.games-lobby').data('initial-cat'); var catContainer = $('.games-lobby').data('cat-container'); var slotsSwitch = $('.games-lobby').data('slots-switch'); const urlParams = new URLSearchParams(window.location.search); const category = urlParams.get('category'); const provider = urlParams.get('provider'); if (category) { initCat = category === 'provider' ? provider : category; } if (isMobile) { initCat = "mobile" + initCat.toLowerCase(); } // GamesLobby.init( // url, -> games url feed // category, -> initial category to load (set in html as data attribute) // loppyWrapper, -> css class given to outer lobby container // paginateStart, -> should always default to 0 on init // paginateEnd, -> number of games to show on pagination // searchWrapper, -> the search panel class // categoryWrapper -> *optional* used only if categories are not part of games lobby // ) GameFavourites.init(catContainer); RecentGames.init(); var brandID = $('body').attr('data-brand'); if (typeof brandID !== "undefined") { GamesLobby.init('sharedGamesAPI',initCat, ".games-lobby", 0, $('.games-lobby').data('games-count'), '.search-controls', catContainer, slotsSwitch); } else{ GamesLobby.init("ajax/gamesxml.php",initCat, ".games-lobby", 0, $('.games-lobby').data('games-count'), '.search-controls', catContainer, slotsSwitch); } setTimeout(function(){ var position = location.hash.split("#")[1]; if (typeof position !== "undefined") { $('html, body').animate({ scrollTop: $("[name='"+ position +"']").offset().top - 100, },500,'linear'); } }, 3000); } }); // Defined at the end on purpose, otherwise claims function not defined function imageFallbackHandler(_this, imagePath){ _this.onerror = null; // To prevent potential infinite loops const dotExtensionPos = imagePath.lastIndexOf('.'); const extension = imagePath.slice(dotExtensionPos + 1); const fallbackExtension = GAMES_IMAGE_FORMAT_FALLBACK[extension]; if (!!fallbackExtension) { const newSrc = imagePath.substr(0, dotExtensionPos) + '.' + fallbackExtension; _this.src = newSrc; } }